package com.excel.easyExcel.exception;

import com.excel.easyExcel.result.Impl.ResultCode;
import com.excel.easyExcel.result.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * @author Xinjie
 * @date 2023/4/25 17:14
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(value = {ImportException.class})
    public ResultVo handleImportException(ImportException e){
        return new ResultVo(ResultCode.FAILED,e.getMessage());
    }

    @ExceptionHandler(value = {UnsupportedEncodingException.class})
    public ResultVo handleUnsupportedEncodingException(UnsupportedEncodingException e){
        return new ResultVo(ResultCode.FAILED,e.getMessage());
    }

    @ExceptionHandler(value = {IOException.class})
    public ResultVo handleIOException(){
        return new ResultVo(ResultCode.FAILED,"IO异常");
    }
}
